package com.ws.common.base.dao;

import com.ws.common.base.entity.Columns;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface BaseMapper<T> {
	
	@Select("select * from INFORMATION_SCHEMA.Columns where TABLE_SCHEMA=#{schema} and TABLE_NAME=#{tableName}  order by ordinal_position")
	public List<Columns> columnsList(@Param("schema") String schema, @Param("tableName") String tableName);
	
	@Delete("delete from ${tableName} where ${idName}=#{id}")
	public Integer delete(@Param("tableName") String tableName,@Param("idName") String idName,@Param("id")  Object id);
	
	@Insert("insert into ${tableName}( ${field} ) values( ${value} )")
    public Integer insert(@Param("t")  T t,@Param("tableName") String tableName,@Param("field") String field,@Param("value") String value);
    
    @Update("update ${tableName} set ${sql} where ${filter} ")
    public Integer update(@Param("t")  T t,@Param("tableName") String tableName,@Param("sql") String sql,@Param("filter") String filter);
    
    @Select("select * from ${tableName} where ${idName}=#{id}")
    public Map<String,Object> read(@Param("tableName") String tableName,@Param("idName") String idName,@Param("id")  Object id);
    
    @Select("select * from ${tableName} ${filter}")
    public List<Map<String,Object>> listByMap(@Param("tableName") String tableName, @Param("t") Map<String ,Object> map, @Param("filter") String filter);

}
